﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.ContentManagement.Drivers;
using RaisingStudio.Trigger.Models;
using Orchard.ContentManagement;

namespace RaisingStudio.Trigger.Drivers
{
    public class TriggerLogPartDriver : ContentPartDriver<TriggerLogPart>
    {
        protected override DriverResult Display(TriggerLogPart part, string displayType, dynamic shapeHelper)
        {
            return ContentShape("Parts_TriggerLog",
                () => shapeHelper.Parts_TriggerLog(
                    TriggerId: part.TriggerId,
                    Title: part.Title,
                    Event: part.Event,
                    Condition: part.Condition,
                    Action: part.Action,
                    ContextContentType: part.ContextContentType,
                    ContextContentId: part.ContextContentId,
                    Status: part.Status,
                    ConditionResult: part.ConditionResult,
                    ActionResult: part.ActionResult,
                    TriggerBeginTime: part.TriggerBeginTime,
                    TriggerEndTime: part.TriggerEndTime
                    ));
        }


        //GET
        protected override DriverResult Editor(TriggerLogPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_TriggerLog_Edit",
                () => shapeHelper.EditorTemplate(
                    TemplateName: "Parts/TriggerLog",
                    Model: part,
                    Prefix: Prefix));
        }

        //POST
        protected override DriverResult Editor(TriggerLogPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}